import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '*',
    redirect: '/index'
  },
  {
    name: 'index',
    path: '/index',
    meta: { title: '首页', menuUrl: '/main', },
    component: () => import('./view/main/index'),
  },
  {
    name: 'login',
    path: '/login',
    meta: { title: '登陆',menuUrl: '/login', },
    component: () => import('./view/auth/login'),
  }

];

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});


export default router;
